﻿#include "CFDPostOperatorsSlice.h"

#include "CFDPostUIComponents/CFDPostTreeWidget.h"
#include "CFDPostDataManager/CFDPostDataManager.h"

#include "CFDPostGUIDialog/CFDPostSliceDialog.h"
#include "GUIFrame/MainWindow.h"
#include "GUIFrame/MainTreeWidget.h"

#include "OperatorsInterface/GraphEventOperator.h"
#include "OperatorsInterface/ParaWidgetInterfaceOperator.h"
#include "CFDPost/CFDPostOperatorsInterface/CFDPostGraphEventOperator.h"
#include "CFDPost/CFDPostOperatorsGUI/CFDPostOperModelTreeMouseEvent.h"

#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Interface/FITKInterfaceCFDPost/FITKCFDPost3DManager.h"
#include "FITK_Interface/FITKInterfaceCFDPost/FITKCFDPostData.h"

namespace OperModel {
CFDPostOperatorsSlice::CFDPostOperatorsSlice() {

}

bool CFDPostOperatorsSlice::execGUI()
{
    //获取树节点当前数据对象id
    if (_senderName == "actionSliceCreate") {
        GUI::CFDPostSliceDialog* dialog = new GUI::CFDPostSliceDialog(
                        DataManager::CFDPostDataManager::getInstance()->getTreeCurrentDataID(), this, true);
        dialog->show();     
    } else if (_senderName == "actionSliceEdit") {
        int objID = -1;
        argValue(objID_String, objID);

        if (objID <= 0) {
            return false;
        }

        GUI::CFDPostSliceDialog* dialog = new GUI::CFDPostSliceDialog(objID, this, false);
        dialog->show();
    }

    return false;
}

bool CFDPostOperatorsSlice::execProfession() {
    Interface::FITKCFDPost3DManager* manager =
                    FITKAPP->getGlobalData()->getPostData<Interface::FITKCFDPostData>()->getPostDataManager();

    if (manager == nullptr)
    {
        return false;
    }

    // 获取文件数据
    EventOper::CFDPostGraphEventOperator* graphOper =
                    FITKOPERREPO->getOperatorT<EventOper::CFDPostGraphEventOperator>("OperGraphPreprocess");//获取OperGraphPreprocess实例

    if (graphOper == nullptr)
    {
        return false;
    }

    // 获取文件树的相关数据
    GUIOper::CFDPostOperModelTreeMouseEvent* treeOper =
                    FITKOPERREPO->getOperatorT<GUIOper::CFDPostOperModelTreeMouseEvent>("CFDPostModelTreeEvent");//获取ModelTreeEvent实例？

    if (treeOper == nullptr)
    {
        return false;
    }

    int objID = -1;
    argValue(objID_String, objID);
    Interface::FITKAbstractCFDPostData* data = manager->getDataByID(objID);

    if (data)
    {
        graphOper->updateSingle(objID);
    }

    treeOper->updateTree();
    return false;
}
}
